defmodule Giom.Repo.Migrations.CreatePtrans do
  use Ecto.Migration

  def change do
    create table(:ptrans,primary_key: false) do
      add :doc_no, :string, primary_key: true, null: false
      add :date, :utc_datetime
      add :source_code, references(:points,type: :string, column: :point_code, on_delete: :nothing), null: false
      add :target_code, references(:points,type: :string, column: :point_code, on_delete: :nothing), null: false
      add :doc_type,  :string,size: 1
      add :comment,  :string
      add :amount, :decimal
      add :vat_total, :decimal
      add :amount_vat, :decimal
      add :vat_status, :decimal
      add :vat1sum, :decimal
      add :vat8sum, :decimal
      add :vat18sum, :decimal
      add :qty_row, :integer
      add :qty_total, :decimal
      #add :create_user, :string
      #add :edit_user, :string
      add :create_date, :utc_datetime
      add :edit_date, :utc_datetime
      add :expiry_date, :utc_datetime
      add :oper_type,  :string, size: 1
      add :wbill_code,  :string
      add :integration,  :string, size: 1

      timestamps()
    end
    create unique_index(:ptrans, [:doc_no])
    create index(:ptrans, [:source_code])
    create index(:ptrans, [:target_code])
  end
end
